﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLBH.DTO;
using QLBH.DataModel;
using QLBH.Model.Controller;

namespace Module.Category
{
    public partial class AddProductCategoryDlg : Form
    {
        private NhomHangDTO productCategory;

        public NhomHangDTO ProductCategory
        {
            get { return productCategory; }
            
        }
        public AddProductCategoryDlg()
        {
            InitializeComponent();

            productCategory = new NhomHangDTO();
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBoxName.Text))
            {
                MessageBox.Show("Bạn phải nhập tên Nhóm Hàng", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            productCategory.GhiChu = textBoxComment.Text;
            productCategory.TenNH = textBoxName.Text;
            AddProductCategory();

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
        public void AddProductCategory()
        {
            try
            {
                NhomHang procate = NhomHangAssembler.ToEntity(ProductCategory);
                productCategory=ProductCategoryController.Instance.Add(procate).ToDTO();
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
